package org.example.cake.service.impl;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.example.cake.entity.Cake;
import org.example.cake.mapper.CakeMapper;
import org.example.cake.service.CakeService;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CakeServiceImpl implements CakeService{

    @Resource
    private CakeMapper cakeMapper;

    @Override
    public int deleteByPrimaryKey(Integer cakeid) {
        return cakeMapper.deleteByPrimaryKey(cakeid);
    }

    @Override
    public int insert(Cake record) {
        return cakeMapper.insert(record);
    }

    @Override
    public int insertSelective(Cake record) {
        return cakeMapper.insertSelective(record);
    }

    @Override
    public Cake selectByPrimaryKey(Integer cakeid) {
        return cakeMapper.selectByPrimaryKey(cakeid);
    }

    @Override
    public int updateByPrimaryKeySelective(Cake record) {
        return cakeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Cake record) {
        return cakeMapper.updateByPrimaryKey(record);
    }
    // 根据分类id查询蛋糕集合
    @Override
    public List<Cake> getCakeListByCategoryId(Integer categoryid) {
        return  cakeMapper.getCakeListByCategoryId(categoryid);
    }
    /**
     * 根据蛋糕id查询蛋糕信息
     * @param cakeid 蛋糕id
     * @return 蛋糕信息
     */
    @Override
    public Cake getCakeById(Integer cakeid) {
        return cakeMapper.getCakeById(cakeid);
    }

    @Override
    public List<Cake> getCakeList( String cakename,Integer status) {
        return cakeMapper.getAllCake(cakename,status);
    }
    @Override
    public int updateCakeHou(List<Long> cakeId) {
        return cakeMapper.updateCakeHou(cakeId);
    }

    @Override
    public int updateCakeInfo(Cake cake) {
        return cakeMapper.updateCakeInfo(cake);
    }

    /**
     * 根据传过来的关键字模糊查询
     * @Date 2025-07-28 谭丽娜
     * @param keyword 蛋糕名字
     * @return
     */
    public List<Cake> searchCake(String keyword) {
        // 将关键词拆分成单个字符并用%连接（生成"草%莓%蛋%糕"模式）
        String pattern = keyword.chars()
                .mapToObj(c -> String.valueOf((char) c))
                .collect(Collectors.joining("%", "%", "%"));
        return cakeMapper.findByPattern(pattern);
    }
    /**
     * 查询新品蛋糕
     * @return 蛋糕集合
     */
    public List<Cake> selectNewCakeList(){
        return cakeMapper.selectNewCakeList();
    }

    /**
     * 查询精选蛋糕
     * @return 蛋糕集合
     */
    public List<Cake> selectChoiceCakeList(){
        return cakeMapper.selectChoiceCakeList();
    }

    @Override
    public List<Cake> getAllCakes() {
        return cakeMapper.selectAllCakes();
    }

    @Override
    public Cake getCake(Integer cakeid) {
        return cakeMapper.getCake(cakeid);
    }

    @Override
    public Integer ifcakeStatus(Integer cakeid) {
        return cakeMapper.ifcakeStatus(cakeid);
    }
}
